package com.lych.dubbo.api;

import com.lych.model.mongo.FocusUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class UserFocusApiImpl implements UserFocusApi{

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 保存userFocus
     * @param focusUser
     */
    @Override
    public void save(FocusUser focusUser) {
        mongoTemplate.save(focusUser);
    }

    /**
     * 删除userFocus
     */
    @Override
    public void delete(Long userId, Long followUserId) {
        Query query = Query.query(Criteria.where("userId").is(userId)
                .and("followUserId").is(followUserId));
//        FocusUser focusUser1 = mongoTemplate.findOne(query, FocusUser.class);
        mongoTemplate.remove(query,FocusUser.class);
    }
}
